<?php

declare(strict_types=1);

namespace App\CustHub\Mapper;

use App\CustHub\Model\ChRoomInviteScheme;
use Hyperf\Cache\Annotation\Cacheable;
use Hyperf\Config\Annotation\Value;
use Hyperf\Database\Concerns\BuildsQueries;
use Hyperf\Database\Model\Builder;
use Hyperf\Database\Model\Model;
use Mine\Abstracts\AbstractMapper;
use Mine\MineModel;

class ChRoomInviteSchemeMapper extends AbstractMapper
{

    #[Value('cache.default.prefix')]
    protected string $prefix;

    public function assignModel()
    {
        $this->model = ChRoomInviteScheme::class;
    }

    /**
     * @param mixed $id
     * @return ChRoomInviteScheme|Model|string|Builder|BuildsQueries|null
     */
    #[Cacheable(prefix: 'room_invite_scheme',value: '#{id}',ttl: 15 * 60)]
    public function findById(mixed $id): ChRoomInviteScheme|Model|string|Builder|BuildsQueries|null
    {
        return $this->model::query()->where('id',$id)->first();
    }

    public function delCache(mixed $id): void
    {
        $redis = redis();
        $keyOne = $this->prefix . 'room_invite_scheme:'.$id;
        $redis->del([$keyOne]);
    }
}